# -*- coding = utf-8 -*-
# @Time    : 2025/3/31 下午8:02
# @Author  : yqk
# @File    : 防止检测1.py
# @Software: PyCharm

import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

# 配置Chrome选项
opt = Options()
opt.add_argument("--disable-blink-features=AutomationControlled")
opt.add_experimental_option('excludeSwitches', ['enable-automation'])
opt.add_experimental_option("detach", True)

# 设置ChromeDriver路径
service = Service(r'D:\python-code\chromedriver-win64\chromedriver.exe')

# 以utf-8编码方式打开文件
with open(r'D:\python-code\python-spider\stealth.min.js', encoding='utf-8') as f:
    js = f.read()

# 初始化浏览器
browser = webdriver.Chrome(service=service, options=opt)

#执行JavaScript防止检测
browser.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
    "source": js
})

# 等待页面加载
browser.implicitly_wait(5)
browser.maximize_window()

# 访问页面
url = 'https://bot.sannysoft.com/'
browser.get(url)
